forum

Home / DeveloperSection / Forums / Add attribute to the body failed

Add attribute to the body failed

Anonymous User 1701 22-Aug-2014

I have an asp.net web page.

The code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Works.Login" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head runat="server">
      <title></title>
      <link rel="stylesheet" type="text/css" href="/styles/source/style.css" />
   </head>
   <body id="PageBody" runat="server">
      <form id="form1" runat="server">
         <div style="text-align: center" >
And in code behind I want to add something to the body attribute.
protected void Page_PreRender(object sender, EventArgs e)
{
        if (PageBody != null)
        {
            PageBody.Attributes.Add("class", "some_image");

However I found it doesn't work at all. I stepped through into the code and found there is an exception.

InnerText = '((System.Web.UI.HtmlControls.HtmlContainerControl)(((System.Web.UI.HtmlControls.HtmlGenericControl)(PageBody)))).InnerText' threw an exception of type 'System.Web.HttpException'}

Thanks for your help.


c# c# 
Updated on 22-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By